<?php
/**
 * 
 * @author yuxun
 *
 */

class ModSynchroInfo extends Model {

    protected $table = 'synchro_info';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbOss;
    }

    public function addmuch($params){
    	$result = $this->getDbConnection()->multiInsert($params, $this->table, FALSE);
    	return $result;
    }
    
    public function select($params){
    	$table = $this->table;

    	$where .= " WHERE classify = :classify ";
    	$args['classify'] = $params['classify'];

    	if(!empty($params['classify_id'])){
    		$where .= " AND classify_id = :classify_id ";
    		$args['classify_id'] = $params['classify_id'];
    	} 

    	if(!empty($params['status'])){
    		$where .= " AND status = :status ";
    		$args['status'] = $params['status'];
    	}

    	$fields = "*";
    	$sql = "SELECT {$fields} FROM {$table} {$where}";   	
    	$data = $this->getDbConnection()->query($sql, $args);    	
    	return $data;
    }
    
    public function getServerIden($server_array_ids,$classify,$classify_iden){
    	$table = $this->table;
    	//$sql = "SELECT * FROM {$table} where classify='{$classify}' and classify_iden='{$classify_iden}' and server_id in ($server_array_ids) ";
    	
    	$sql = "SELECT si.*,ac.duration,a.start_time,a.is_open as a_is_open FROM synchro_info as si ";
        $sql .= " INNER JOIN activity as a on a.id = si.classify_id ";
        $sql .= " INNER JOIN activity_category as ac on ac.id = a.category_id ";
        $sql .= " where si.classify='{$classify}' and si.classify_iden='{$classify_iden}' and si.server_id in ($server_array_ids) ";
        $sql .= " and a.status in (1,2,4,5) and si.status = 1 ";
    	
    	$data = $this->getDbConnection()->query($sql, $args);
    	return $data;
    }
    
    
    
} 